home *** CD-ROM | disk | FTP | other *** search
- #!/sprite/cmds/csh -f
- #
- # A script to generate (or regenerate) the Makefile for a directory
- # consisting solely of header files.
- #
- # We assume we were invoked from mkmf. Parameters passed in from mkmf
- # through environment variables:
- #
- # MKMFDIR directory containing prototype makefiles
- # MAKEFILE name of makefile to create
- # SUBTYPE additional information, telling whether this
- # is an X directory, Sprite directory, etc.
- #
-
- #
- # Argument processing. (Generalized form, even though just one flag so far.)
- #
- while ($#argv >= 1)
- if ("$1" == '-x') then
- set echo
- endif
- shift
- end
-
- set subtype=$SUBTYPE
- set tmp=`expr $cwd : '.*/\(include.*\)$'`
- switch ($subtype)
- case sprite:
- set includedir=/sprite/lib/$tmp
- breaksw
- case x:
- set includedir=/a/X/lib/$tmp
- breaksw
- default:
- echo Unknown header subtype "$subtype"
- exit 1
- endsw
- set pref='[a-z_A-Z]'
- set makefile=$MAKEFILE
-
- if (-e $makefile.proto) then
- set proto=$makefile.proto
- else
- set proto="${MKMFDIR}/Makefile.hdrs"
- endif
-
- echo "Generating a Makefile for $includedir headers using $proto"
-
- set nonomatch
- set hdrs =( ${pref}*.h )
- #
- # Check to see if there were any headers. The first check (size == 1)
- # is only necessary because the second check will cause an error if
- # hdrs contains more than 1024 bytes.
- #
- if ($#hdrs == 1) then
- if ("$hdrs" == "${pref}*.h") set hdrs=()
- endif
- unset nonomatch
- set subDirs="`find * -type d ! -name RCS -prune -print`"
- set distdir=($DISTDIR)
-
- #
- # Use sed to substitute various interesting things into the prototype
- # makefile. The code below is a bit tricky because some of the variables
- # being substituted in can be very long: if the substitution is passed
- # to sed with "-e", the entire variable must fit in a single shell argument,
- # with a limit of 1024 characters. By generating a separate script file
- # for the very long variables, the variables get passed through (to the
- # script file) as many arguments, which gets around the length problem.
- #
-
- rm -f mkmf.tmp.sed
- echo s,"@(HDRS)",$hdrs,g > mkmf.tmp.sed
- cat $proto | sed -f mkmf.tmp.sed \
- -e "s,@(DATE),`date`,g" \
- -e "s,@(INCLUDEDIR),$includedir,g" \
- -e "s,@(MAKEFILE),$makefile,g" \
- -e "s,@(SUBDIRS),$subDirs,g" \
- -e "s,@(TEMPLATE),$proto,g" \
- -e "s,@(DISTDIR),$distdir,g" \
- -e "s,@(TYPE),$subtype,g" \
- > $makefile
- rm -f mkmf.tmp.sed
-